import pymysql
from pyecharts.charts import Bar, Pie
from pyecharts import options

db = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    passwd='1234',
    database='crawlerdemo',
    charset='utf8',
)
cursor = db.cursor()

sql = ("SELECT job_place, COUNT(job_id) "
       "FROM job "  # 替换为您的表名  
       "GROUP BY job_place ")
#       "ORDER BY COUNT(job_id) DESC "
#       "LIMIT 5;")
try:
    cursor.execute(sql)
    res = cursor.fetchall()
    pie = Pie()
    pie.add("单位/个", res, radius=["0%", "75%"], )
    pie.set_global_opts(title_opts=options.TitleOpts(title="各城市岗位数量"))
    pie.render("pienum.html")
except:
    print("查询出错啦")
